package model;

import java.io.IOException;

public class InstrumentedNode extends Node{

	long beforeTime = 0;
	//private long startTime = 0;
	
	public InstrumentedNode(Position location, Zone zone, String ID,
			String basePath, int mean, long sTime, int numberOfNodes) throws IOException {
		super(location, zone, ID, basePath, mean, numberOfNodes);
		//this.startTime = sTime;
	}
	
	protected void logAddObservation(Position location, Observation observation, int size){
		writeMessageToFile("Add Observation,"+observation.getLocation().getZone()+","+observation.getObservations().toString()+","+size, location);
	}
	//this is used to test m2, number of reported events
	@Override
	protected void logObservation(Observation observation){
		//added observation and current time stamp to compare time difference
		writeMessageToFile("Received Observation: "+observation.getObservations().toString() + "," + observation.getObserver() + "," +observation.getTimeStamp(), observation.getLocation());
	}
	//this is used to test m2, number of obs returned from given location
	@Override
	public void logGetBeforeObs(){
		//added observation and current time stamp to compare time difference
		//writeMessageToFile("Before Get Observations", loc);
		beforeTime = System.currentTimeMillis();
	}
	public void logGetAfterObs(Position location, int obsSize){
		writeMessageToFile("After Get Observation," + beforeTime + "," +location.getZone()+","+obsSize, location);
	}
	
	@Override
	protected void logStartUpTime (Position location) {
		//writeMessageToFile("After Startup," + startTime, location);
	}

	public static void main(String[] args) {

		// args[0] is the zone name
		// args[1] is the zone dimension (square: dimension x dimension)
		// args[2] is the zone's "window" of interest
		// args[3] is the node's ID
		// args[4] is the base path
		// args[5] is the mean for log normal distribution
		// args[6] is the number of nodes running in zone

		try {
			// added this file to test m3 
			// this will create a file to log node creation time
			// this can be removed after testing m3 on slide 18
			
			long sTime = System.currentTimeMillis();
			System.out.println(args[0] + Integer.valueOf(args[1]) + Integer.valueOf(args[2]));
			Zone zone = new Zone(args[0], Integer.valueOf(args[1]), Integer.valueOf(args[2]));
			Position location = new Position ((int) (zone.getDimension() / 2), 
					(int) (zone.getDimension() / 2), 
					args[0]);
			Node iNode = new InstrumentedNode(location, zone, args[3], args[4], new Integer(args[5]), sTime, new Integer(args[6]));

			iNode.run();

		} catch (IOException e) {
			e.printStackTrace();
		}


	}

}
